<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
{js href="/static/admin/lib/html5shiv.js,/static/admin/lib/respond.min.js"}
<![endif]-->
{css href="/static/admin/static/h-ui/css/H-ui.min.css,/static/admin/static/h-ui.admin/css/H-ui.admin.css,/static/admin/lib/Hui-iconfont/1.0.8/iconfont.css,/static/admin/static/h-ui.admin/skin/default/skin.css,/static/admin/static/h-ui.admin/css/style.css,/static/admin/static/gloab.css,/static/admin/lib/webuploader/0.1.5/webuploader.css"}
<!--[if IE 6]>
{js href="/static/admin/lib/DD_belatedPNG_0.0.8a-min.js"}
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>添加试题分组 - 试题管理</title>
</head>
<body>
<article class="page-container">
	<form class="form form-horizontal" id="form-admin-edit" action="/admin/questions/answer">
		<input type="hidden" name="qid" value="{$get.qid}">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>标题：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="" placeholder="" id="title" name="title">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>题目类型：</label>
			<div class="formControls col-xs-8 col-sm-9 skin-minimal">
				{foreach $config['type'] as $key => $_type}
				<div class="radio-box">
					<input name="type" type="radio" class="type" id="type-{$key}" value="{$key}" {if $key == 1}checked{/if}>
					<label for="type-{$key}">{$_type}</label>
				</div>
				{/foreach}
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">题目解析：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<textarea name="analysis" cols="" rows="" class="textarea"  placeholder="题目解析...100个字符以内" dragonfly="true" ></textarea>
			</div>
		</div>
		<div class="row cl opt">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>添加答案：</label>
			<div class="opts row col-xs-8 col-sm-9 formControls">
				<div class="formControls col-xs-5 col-sm-5">
					<input type="text" class="input-text" value="" placeholder="A:" name="opttitle[A]">
				</div>
				<label class="form-label col-xs-3 col-sm-3">正确答案：</label>
				<div class="formControls col-xs-4 col-sm-4 skin-minimal">
					{foreach $optConfig['is_answer'] as $key => $_is_answer}
					<div class="radio-box">
						<input name="is_answer[A]" class="is_answer a" type="radio" id="is_answer[A]-{$key}" value="{$key}" {if $key == 1}checked{/if}>
						<label for="is_answer[A]-{$key}">{$_is_answer}</label>
					</div>
					{/foreach}
				</div>
			</div>
			<label class="form-label col-xs-3 col-sm-3"></label>
			<div class="opts row col-xs-8 col-sm-9 formControls">
				<div class="formControls col-xs-5 col-sm-5">
					<input type="text" class="input-text" value="" placeholder="B:" name="opttitle[B]">
				</div>
				<label class="form-label col-xs-3 col-sm-3">正确答案：</label>
				<div class="formControls col-xs-4 col-sm-4 skin-minimal">
					{foreach $optConfig['is_answer'] as $key => $_is_answer}
					<div class="radio-box">
						<input name="is_answer[B]" class="is_answer b" type="radio" id="is_answer[B]-{$key}" value="{$key}" {if $key == 0}checked{/if}>
						<label for="is_answer[B]-{$key}">{$_is_answer}</label>
					</div>
					{/foreach}
				</div>
			</div>
			<label class="form-label col-xs-3 col-sm-3"></label>
			<div class="opts row col-xs-8 col-sm-9 formControls">
				<div class="formControls col-xs-5 col-sm-5">
					<input type="text" class="input-text" value="" placeholder="C:" name="opttitle[C]">
				</div>
				<label class="form-label col-xs-3 col-sm-3">正确答案：</label>
				<div class="formControls col-xs-4 col-sm-4 skin-minimal">
					{foreach $optConfig['is_answer'] as $key => $_is_answer}
					<div class="radio-box">
						<input name="is_answer[C]" type="radio" class="is_answer c" id="is_answer[C]-{$key}" value="{$key}" {if $key == 0}checked{/if}>
						<label for="is_answer[C]-{$key}">{$_is_answer}</label>
					</div>
					{/foreach}
				</div>
			</div>
			<label class="form-label col-xs-3 col-sm-3"></label>
			<div class="opts row col-xs-8 col-sm-9 formControls">
				<div class="formControls col-xs-5 col-sm-5">
					<input type="text" class="input-text" value="" placeholder="D:" name="opttitle[D]">
				</div>
				<label class="form-label col-xs-3 col-sm-3">正确答案：</label>
				<div class="formControls col-xs-4 col-sm-4 skin-minimal">
					{foreach $optConfig['is_answer'] as $key => $_is_answer}
					<div class="radio-box">
						<input name="is_answer[D]" type="radio" class="is_answer d" id="is_answer[D]-{$key}" value="{$key}" {if $key == 0}checked{/if}>
						<label for="is_answer[D]-{$key}">{$_is_answer}</label>
					</div>
					{/foreach}
				</div>
			</div>
		</div>
		{if can('admin/questions/Answer/save')}
			<div class="row cl">
				<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
					<input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
				</div>
			</div>
		{/if}
	</form>
</article>

<!--_footer 作为公共模版分离出去-->
{js href="/static/admin/lib/jquery/1.9.1/jquery.min.js,/static/admin/lib/layer/2.4/layer.js,/static/admin/static/h-ui/js/H-ui.js,/static/admin/static/h-ui.admin/js/H-ui.admin.js"}
<!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
{js href="/static/admin/lib/jquery.validation/1.14.0/jquery.validate.js,/static/admin/lib/jquery.validation/1.14.0/validate-methods.js,/static/admin/lib/jquery.validation/1.14.0/messages_zh.js,/static/admin/static/gloab.js,/static/admin/lib/webuploader/0.1.5/webuploader.min.js,/static/admin/lib/My97DatePicker/4.8/WdatePicker.js"}
<script type="text/javascript">
$(function(){

    $('.textarea').Huitextarealength({
        maxlength:100
    });

	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
	
	$("#form-admin-edit").validate({
		rules:{
            title : {
                required : true,
                rangelength: [1, 100]
            },
            type : {
                required: true,
                min: 1,
                digits: true
            },
            qid : {
                required: true,
                digits: true,
                min: 1
            },
			"opttitle[A]": {
                required: true,
			},
            "opttitle[B]": {
                required: true,
            },
            "opttitle[C]": {
                required: true,
            },
            "opttitle[D]": {
                required: true,
            }
		},
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
			$(form).ajaxSubmit({
				type: 'post',
                url: $(form).attr('action'),
                data: $(form).serialize(),
                success:function(data){
					layer.msg('新增成功',{icon:1,time:1000});
                },
                error:function(XmlHttpRequest, textStatus, errorThrown){
                    let errstr = XmlHttpRequest.responseText;
                    if ( errstr ) {
                        layer.msg($.parseJSON(errstr).message,{icon:5,time:1000});
                    } else {
                        layer.msg('服务错误!',{icon:5,time:1000});
                    }
                }
			});
			// var index = parent.layer.getFrameIndex(window.name);
			// parent.$('.btn-refresh').click();
			// parent.layer.close(index);
			return false;
		}
	});
	$('.is_answer').on('ifClicked', function(event){
	    let _this = $(this);
	    let type = $('input[name=type]:checked').val();
	    let opt = _this.attr('class').split(' ')[1];
	    if ( type == 1 ) {
            $('.is_answer').parent().parent().parent().parent().find('.is_answer').each(function(){
				let $_this = $(this);
				if ( $_this.attr('class').split(' ')[1] !== opt ) {
				    if ( $_this.val() == 0 ) {
                        $_this.iCheck('check');
					} else {
                        $_this.iCheck('uncheck');
					}
				} else {
                    if ( _this.val() != $_this.val() ) {
                        $_this.iCheck('uncheck');
                    }
				}
			});

			if ( _this.val() == 0 ) {
				switch ( opt ) {
					case 'a':
						$('.b').each(function(){
							let optThis = $(this);
							if ( optThis.val() == 1 ) {
								optThis.iCheck('check');
							} else {
								optThis.iCheck('uncheck');
							}
						});
						break;
					case 'b':
						$('.c').each(function(){
							let optThis = $(this);
							if ( optThis.val() == 1 ) {
								optThis.iCheck('check');
							} else {
								optThis.iCheck('uncheck');
							}
						});
						break;
					case 'c':
						$('.d').each(function(){
							let optThis = $(this);
							if ( optThis.val() == 1 ) {
								optThis.iCheck('check');
							} else {
								optThis.iCheck('uncheck');
							}
						});
						break;
					case 'd':
						$('.a').each(function(){
							let optThis = $(this);
							if ( optThis.val() == 1 ) {
								optThis.iCheck('check');
							} else {
								optThis.iCheck('uncheck');
							}
						});
						break;
				}
			}
		}
	});
	$('input[name=type]').on('ifClicked', function(){
	    let _this = $(this);
	    if ( _this.val() == 1 ) {
            $('.is_answer').parent().parent().parent().parent().find('.is_answer').each(function(){
                let $_this = $(this);
                if ( $_this.attr('class').split(' ')[1] !== 'a' ) {
                    if ( $_this.val() == 1 ) {
                        $_this.iCheck('uncheck');
                    } else {
                        $_this.iCheck('check');
                    }
                } else {
                    if (  $_this.val() == 1 ) {
                        $_this.iCheck('check');
					} else {
                        $_this.iCheck('uncheck');
					}
				}
            })
		}
	})
});

</script> 
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>